package com.example.service.impl;

import com.example.mapper.PatriarchMapper;
import com.example.pojo.*;
import com.example.service.PatriarchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service
public class PatriarchServiceImpl implements PatriarchService {


    @Autowired
    private PatriarchMapper patriarchMapper;


    @Override
    public List<HomeWork> list(String username) {

        List<HomeWork> homeWorkList = patriarchMapper.list(username);

        return homeWorkList;
    }

    @Override
    public Patriarch login(Patriarch patriarch) {
        return patriarchMapper.getByUserNameAndPassword(patriarch);
    }

    @Override
    public Select showTask(String username) {
        String name = patriarchMapper.getName(username);
        List<StudentHomeWork> list = patriarchMapper.getByhw(username);
        Select select = new Select(name, list);
        return select;
    }

    @Override
    public Patriarch showMine(String username) {
        Patriarch patriarch = patriarchMapper.showMain(username);
        return patriarch;
    }

    @Override
    public StudentHomeWork showDeta(SelectDeta selectDeta) {

        String username = selectDeta.getUsername();
        Integer id = selectDeta.getId();
        StudentHomeWork studentHomeWork = patriarchMapper.getHomeWorkById(username, id);
        return studentHomeWork;
    }

    @Override
    public void addOpinion(Opinion opinion) {
        Integer id = patriarchMapper.getId(opinion);
        opinion.setUserid(id);
        opinion.setExpirdateTime(LocalDateTime.now());
        opinion.setCreateTime(LocalDateTime.now());
        opinion.setUpdateTime(LocalDateTime.now());
        patriarchMapper.addOpinion(opinion);
    }

    @Override
    public List<Task> listTask(String username) {
        List<Task> taskList = patriarchMapper.listTask(username);

        return taskList;
    }

    @Override
    public List<Progress> listProgress(String username) {
        return patriarchMapper.listProgress(username);
    }

    @Override
    public List<Plan> listPlan(String username) {
        return patriarchMapper.listPlan(username);
    }

    @Override
    public void setPassWord(Pass pass) {
        patriarchMapper.setPassWord(pass);
    }

    @Override
    public void uplodeHomeWork(String username, Integer id, String imgUrl) {
        Integer sid = patriarchMapper.selId(username);
        LocalDateTime now = LocalDateTime.now();
        patriarchMapper.uplodeHomeWork(sid, id, imgUrl, now);
    }

    @Override
    public List<Student> listStudent(String username) {
        List<Student> studentList = patriarchMapper.listStudent(username);
        return studentList;
    }

    @Override
    public List<Teacher> getTeacherByClass(String username) {
        List<Teacher> teacherList = patriarchMapper.getTeacherByClass(username);
        return teacherList;
    }

    @Override
    public SelectMoney getClassFee(String username) {
        Float sum = patriarchMapper.getSum(username);
        List<ClassFee> classFeeList = patriarchMapper.getClassFee(username);
        SelectMoney selectMoney = new SelectMoney(sum, classFeeList);
        return selectMoney;
    }

    @Override
    public List<Announcemen> getAnnoun(String username) {
        Integer greadClassId = patriarchMapper.greadClassId(username);
        List<Announcemen> announcemenList = patriarchMapper.getAnnoun(greadClassId);
        return announcemenList;
    }

    @Override
    public StudentTask showTakeDeta(SelectDeta selectDeta) {
        String username = selectDeta.getUsername();
        Integer id = selectDeta.getId();
        StudentTask studentTask = patriarchMapper.getTaskDetaById(username, id);
        return studentTask;
    }

    @Override
    public void uplodeTask(String username, Integer id, String imgUrl) {
        Integer sid = patriarchMapper.selId(username);
        LocalDateTime now = LocalDateTime.now();
        patriarchMapper.uplodeTask(sid, id, imgUrl, now);
    }
}
